<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>YouTube Thumbnail Downloader</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        
        :root {
            --primary: #FF0000;
            --primary-light: #FF4D4D;
            --dark: #202020;
            --light: #ffffff;
            --gray: #f1f1f1;
            --text: #333333;
        }
        
        body {
            background: linear-gradient(135deg, #f9f9f9 0%, #eeeeee 100%);
            color: var(--text);
            line-height: 1.6;
            min-height: 100vh;
            padding: 20px;
            display: flex;
            flex-direction: column;
            align-items: center;
        }
        
        .container {
            width: 100%;
            max-width: 800px;
            background: var(--light);
            border-radius: 15px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            overflow: hidden;
        }
        
        header {
            background: linear-gradient(135deg, var(--primary), var(--primary-light));
            color: white;
            padding: 25px;
            text-align: center;
        }
        
        .logo {
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 15px;
            margin-bottom: 15px;
        }
        
        .logo-icon {
            background: white;
            width: 50px;
            height: 50px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: var(--primary);
            font-size: 24px;
        }
        
        h1 {
            font-size: 2.2rem;
            margin-bottom: 10px;
        }
        
        .tagline {
            font-size: 1.1rem;
            opacity: 0.9;
        }
        
        .main-content {
            padding: 30px;
        }
        
        .input-section {
            background: var(--gray);
            border-radius: 12px;
            padding: 25px;
            margin-bottom: 25px;
        }
        
        h2 {
            font-size: 1.5rem;
            margin-bottom: 20px;
            color: var(--dark);
            display: flex;
            align-items: center;
            gap: 10px;
        }
        
        .input-group {
            display: flex;
            gap: 10px;
            margin-bottom: 20px;
        }
        
        input {
            flex: 1;
            padding: 15px;
            border: 2px solid #dddddd;
            border-radius: 8px;
            font-size: 16px;
            transition: border-color 0.3s;
        }
        
        input:focus {
            border-color: var(--primary);
            outline: none;
            box-shadow: 0 0 0 3px rgba(255, 0, 0, 0.1);
        }
        
        button {
            padding: 15px 25px;
            border: none;
            border-radius: 8px;
            background: linear-gradient(135deg, var(--primary), var(--primary-light));
            color: white;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s;
            display: flex;
            align-items: center;
            gap: 8px;
        }
        
        button:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(255, 0, 0, 0.2);
        }
        
        button:active {
            transform: translateY(0);
        }
        
        .result-section {
            display: none;
            background: var(--gray);
            border-radius: 12px;
            padding: 25px;
            margin-bottom: 25px;
            text-align: center;
        }
        
        .thumbnail-container {
            margin: 20px 0;
            border-radius: 10px;
            overflow: hidden;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
        }
        
        .thumbnail-container img {
            width: 100%;
            display: block;
        }
        
        .quality-options {
            display: flex;
            justify-content: center;
            gap: 10px;
            margin: 20px 0;
            flex-wrap: wrap;
        }
        
        .quality-btn {
            padding: 10px 20px;
            background: white;
            border: 2px solid #dddddd;
            border-radius: 8px;
            cursor: pointer;
            transition: all 0.3s;
            font-weight: 500;
        }
        
        .quality-btn.active {
            background: var(--primary);
            color: white;
            border-color: var(--primary);
        }
        
        .download-btn {
            background: linear-gradient(135deg, #00c853, #00e676);
            margin: 0 auto;
        }
        
        .instructions {
            background: white;
            border-radius: 12px;
            padding: 25px;
        }
        
        .steps {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
            gap: 20px;
            margin-top: 20px;
        }
        
        .step {
            background: var(--gray);
            border-radius: 10px;
            padding: 20px;
            text-align: center;
        }
        
        .step i {
            font-size: 30px;
            color: var(--primary);
            margin-bottom: 15px;
        }
        
        .step h3 {
            font-size: 1.2rem;
            margin-bottom: 10px;
            color: var(--dark);
        }
        
        .step p {
            color: #666;
        }
        
        footer {
            text-align: center;
            padding: 20px;
            color: #666;
            margin-top: 20px;
        }
        
        @media (max-width: 600px) {
            .input-group {
                flex-direction: column;
            }
            
            button {
                width: 100%;
                justify-content: center;
            }
            
            .quality-options {
                flex-direction: column;
            }
            
            .quality-btn {
                width: 100%;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <header>
            <div class="logo">
                <div class="logo-icon">
                    <i class="fab fa-youtube"></i>
                </div>
                <h1>YouTube Thumbnail Downloader</h1>
            </div>
            <p class="tagline">Download high-quality thumbnails from any YouTube video</p>
        </header>
        
        <div class="main-content">
            <div class="input-section">
                <h2><i class="fas fa-link"></i> Enter YouTube Video URL</h2>
                <div class="input-group">
                    <input type="text" id="video-url" placeholder="https://www.youtube.com/watch?v=..." />
                    <button id="fetch-btn">
                        <i class="fas fa-download"></i> Get Thumbnail
                    </button>
                </div>
                <p>Paste the YouTube video link above and click "Get Thumbnail" to continue.</p>
            </div>
            
            <div class="result-section" id="result-section">
                <h2><i class="fas fa-image"></i> Thumbnail Preview</h2>
                <div class="thumbnail-container">
                    <img id="thumbnail-img" src="" alt="YouTube thumbnail" />
                </div>
                
                <div class="quality-options">
                    <div class="quality-btn active" data-quality="maxres">High Quality</div>
                    <div class="quality-btn" data-quality="sd">Medium Quality</div>
                    <div class="quality-btn" data-quality="hq">Low Quality</div>
                </div>
                
                <button class="download-btn" id="download-btn">
                    <i class="fas fa-download"></i> Download Thumbnail
                </button>
            </div>
            
            <div class="instructions">
                <h2><i class="fas fa-info-circle"></i> How to Use</h2>
                <div class="steps">
                    <div class="step">
                        <i class="fas fa-copy"></i>
                        <h3>Copy URL</h3>
                        <p>Copy the YouTube video URL from your browser's address bar</p>
                    </div>
                    <div class="step">
                        <i class="fas fa-paste"></i>
                        <h3>Paste URL</h3>
                        <p>Paste the URL in the input field above</p>
                    </div>
                    <div class="step">
                        <i class="fas fa-download"></i>
                        <h3>Download</h3>
                        <p>Select quality and download your thumbnail</p>
                    </div>
                </div>
            </div>
        </div>
        
        <footer>
            <p>YouTube Thumbnail Downloader &copy; 2023 - For content creators, students, and bloggers</p>
        </footer>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const videoUrlInput = document.getElementById('video-url');
            const fetchBtn = document.getElementById('fetch-btn');
            const resultSection = document.getElementById('result-section');
            const thumbnailImg = document.getElementById('thumbnail-img');
            const qualityButtons = document.querySelectorAll('.quality-btn');
            const downloadBtn = document.getElementById('download-btn');
            
            let currentQuality = 'maxres';
            let videoId = '';
            let thumbnailUrl = '';
            
            // Add event listener to fetch button
            fetchBtn.addEventListener('click', function() {
                const url = videoUrlInput.value.trim();
                
                if (!url) {
                    alert('Please enter a YouTube video URL');
                    return;
                }
                
                // Extract video ID from different YouTube URL formats
                videoId = extractVideoId(url);
                
                if (!videoId) {
                    alert('Please enter a valid YouTube video URL');
                    return;
                }
                
                // Generate thumbnail URL
                thumbnailUrl = `https://img.youtube.com/vi/${videoId}/${currentQuality}default.jpg`;
                
                // Set thumbnail image source
                thumbnailImg.src = thumbnailUrl;
                
                // Show result section
                resultSection.style.display = 'block';
                
                // Scroll to result section
                resultSection.scrollIntoView({ behavior: 'smooth' });
            });
            
            // Add event listeners to quality buttons
            qualityButtons.forEach(btn => {
                btn.addEventListener('click', function() {
                    qualityButtons.forEach(b => b.classList.remove('active'));
                    this.classList.add('active');
                    currentQuality = this.getAttribute('data-quality');
                    
                    // Update thumbnail if video ID is available
                    if (videoId) {
                        thumbnailUrl = `https://img.youtube.com/vi/${videoId}/${currentQuality}default.jpg`;
                        thumbnailImg.src = thumbnailUrl;
                    }
                });
            });
            
            // Add event listener to download button
            downloadBtn.addEventListener('click', function() {
                if (!thumbnailUrl) {
                    alert('Please fetch a thumbnail first');
                    return;
                }
                
                // Create a temporary anchor element to trigger download
                const a = document.createElement('a');
                a.href = thumbnailUrl;
                a.download = `youtube-thumbnail-${videoId}-${currentQuality}.jpg`;
                document.body.appendChild(a);
                a.click();
                document.body.removeChild(a);
            });
            
            // Function to extract video ID from YouTube URL
            function extractVideoId(url) {
                const regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#&?]*).*/;
                const match = url.match(regExp);
                return (match && match[7].length === 11) ? match[7] : false;
            }
            
            // Example URL for user convenience
            videoUrlInput.value = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ';
        });
    </script>
</body>
</html>